/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mvp.levelup.hashs.map;

import mvp.levelup.hashs.model.Account;
import java.util.Scanner;

/**
 *
 * @author WORKSPOT2
 */
public class AccountTaskMain
{

    private static AccountStorage storage;

    static
    {
        storage = new AccountStorage();
    }

    public static void main(String args[])
    {
        String name;
        double money;
        int currentId = 1;
        Scanner sc = new Scanner(System.in);

        while (true)
        {
            System.out.println("Enter username: ");
            name = sc.nextLine();
            if (!name.equalsIgnoreCase("stop"))
            {
                System.out.println("Enter money: ");
                try
                {
                    money = Double.parseDouble(sc.nextLine());
                    storage.addAccount(name, new Account(currentId, money));
                }
                catch (NumberFormatException ne)
                {
                    System.err.println("Bad money info. Try again");
                }
            }
            else
            {
                break;
            }
        }
        System.out.println("Enter user name to find");
        String nameToFind = sc.nextLine();
        Account found = storage.getAccount(nameToFind);
        if (found != null)
        {
            System.out.println("Money: " + found.getMoney());
        }
        else
        {
            System.out.println("No user found!");
        }
    }
}
